GBML manual / Collision

tile_layer_active

The number of the collision layer that is on in this room right now. A room with no extra layers is always on layer 1. Use it to check before you do something, for example only open a door that is still shut.

Syntax

tile_layer_active() -> int

Returns

int

Description

Gives you the number of the collision layer that is on in this room right now.

var which = tile_layer_active();

Layer 1 is the room the way you first drew it. A room with no extra layers is always on layer 1. It answers for the room the player is in right now.

tile_layer_set_active switches layers. This is the matching question: which one is on?

It knows from the start

When a room loads, the game puts the room back on the layer it was on before. That happens before any object in the room wakes up. So an object's Create event can already ask tile_layer_active() and get the right answer. A door that was opened yesterday and saved reads as open.

A number, not a name

You get the layer's number. Layers do have names in the Room Editor. Out of the box they are only to help you remember what each layer is for, and your code uses numbers. A layer's number never changes. If your project turns on Use layer names in my code, a layer's name is also a word that stands for its number, so tile_layer_active() == west_room_door_open works. See collision layers.

Example

// Press the interact button to open the door if it is shut, or shut it if it is open.
if (action_pressed(interact)) {
    if (tile_layer_active() == 1) {
        tile_layer_set_active(2);
    } else {
        tile_layer_set_active(1);
    }
}

Layer 1 has the door shut and layer 2 has it open. Each press asks which layer is on, and switches to the other one. That makes a door that toggles.

On the GBA

It answers for the room the player is in. Right after a room loads it already holds the layer the room was on before, so a Create event can look at it. It is the layer number, not a name: layer 1 is the room as you first drew it.

See also: tile_layer_set_activeCollision layers